package lee.study.Listfuc;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

class Card {
    public int rank;//牌面值
    public String suit;//花色

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public String toString() {
        return String.format("[%s,%d]",suit,rank);
    }
}

public class pokerCard {
    public static final String[] SUITS = {"♥", "♠", "♦", "♣"};

    //1.买牌
    public static List<Card> buyCard() {
        List<Card> deck=new ArrayList<>();
        for (int i = 0; i <4; i++) {
            for (int j = 1; j <= 13; j++) {
                int rank = j;
                String suit=SUITS[i];
                Card card=new Card(rank,suit);
                deck.add(card);
            }
        }
     return deck;
    }

    //2.洗牌
    private static void swap(List<Card> list,int index,int i){
    //tmp = [index]
    //[index]=[i]
    //[i]=tmp
    Card tmp=list.get(index);
    list.set(index,list.get(i));
    list.set(i,tmp);
    }

    public static void shuffle(List<Card> list){
        for (int i =list.size()-1; i >0 ; i--) {
            Random random=new Random();
            int index=random.nextInt(i);//[0,i）
            swap(list,index,i);
        }
    }

    public static void main(String[] args) {
    List<Card> deck=buyCard();
        System.out.println(deck);
        System.out.println("洗牌");
        shuffle(deck);
        System.out.println(deck);


        //3.三个人，每人 轮流  接牌五张
        List<List<Card>> player=new ArrayList<>();
        List<Card> player1=new ArrayList<>();
        List<Card> player2=new ArrayList<>();
        List<Card> player3=new ArrayList<>();

        player.add(player1);
        player.add(player2);
        player.add(player3);

        for (int i = 0; i <5 ; i++) {
            for (int j=0;j<3;j++){
                Card card=deck.remove(0);
                player.get(j).add(card);
            }
        }
        System.out.println("第一个人的牌");
        System.out.println(player1);
        System.out.println("第二个人的牌");
        System.out.println(player2);
        System.out.println("第三个人的牌");
        System.out.println(player3);
        System.out.println("剩下的牌");
        System.out.println(deck);
    }
}
